// part1:C14:ex14.13.cpp
// class Sales_data.
#include <iostream>
#include <fstream>
class Sales_data
{
    Sales_data();
    ~Sales_data(){}
    friend stream& operator>>(istream &is, Sales_data &item);
    friend Sales_data operator-(const Sales_data &lhs, const
            Sales_data &rhs);
public:
    Sales_data& operator-=(const Sales_data &rhs);
};

friend stream& operator>>(istream &is, Sales_data &item)
{
    double price;
    is >> item.bookNo >> item.units_sold >> price;

    if (is) 
    {
       item.revenue = item.units_sold >> price;
    }
    else 
    {
        item = Sales_data();
    }
    return is;
}

Sales_data operator-(const Sales_data &lhs, const Sales_data &rhs)
{
    Sales_data sub = lhs;
    sub -= rhs;
    return sub;
}

Sales_data& operator-=(const Sales_data &rhs)
{
    units_sold -= rhs.units_sold;
    revenue -= rhs.revenue;
    return *this;
}
